import React, { Component } from 'react';
import JPushModule from 'jpush-react-native';
import { Toast } from 'antd-mobile';
import { Platform, StyleSheet, Text, View, Alert } from 'react-native';
import { MainScreenNavigator, LoginRout } from './src/router/indexRouter'

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' +
    'Cmd+D or shake for dev menu',
  android: 'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});
var Sound = require('react-native-sound');
// Enable playback in silence mode
Sound.setCategory('Playback');
// Load the sound file 'whoosh.mp3' from the app bundle
// See notes below about preloading sounds within initialization code below.
var whoosh = new Sound('success.mp3', Sound.MAIN_BUNDLE, (error) => {
  if (error) {
    console.log('failed to load the sound', error);
    return;
  }
  // loaded successfully
  console.log('duration in seconds: ' + whoosh.getDuration() + 'number of channels: ' + whoosh.getNumberOfChannels());
});

export default class App extends Component {
  
  constructor(props) {
    super(props)
  }

  // jumpSecondActivity = ()=> {
  //   this.props.navigation.navigate('ChooseStationScreen')
  // }
  componentDidMount() {

    // Toast.loading('Loading...', 5, () => {
    //   console.log('Load complete !!!');
    // });
    // JPushModule.cleanTags(success => {
    
    //   console.log("清除标签: ", success);
    // })
    // this.jumpSecondActivity();

    console.log("开始。。。。。。: ");
    JPushModule.notifyJSDidLoad((message) => {
      console.log("启动: " + message);
    });
    // 接收到自定义消息
    JPushModule.addReceiveCustomMsgListener((message) => {
      console.log("receive msg: " + message);
      JPushModule.jumpToPushActivity("MainActivity");
    });
    // 接收到通知消息
    JPushModule.addReceiveNotificationListener((message) => {
      console.log("receive notification: ", message);
      whoosh.setNumberOfLoops(10);
      whoosh.play();
      // JPushModule.jumpToPushActivity("MainActivity");
    })
    // 打开通知消息
    JPushModule.addReceiveOpenNotificationListener((message) => {
      console.log("receive notification: " + message);
      whoosh.pause();
      // JPushModule.jumpToPushActivity("MainActivity");
      // this.jumpSecondActivity();
    })
  }

  componentWillUnmount() {
    JPushModule.removeReceiveCustomMsgListener();
    JPushModule.removeReceiveNotificationListener();
    whoosh.pause();
  }

  render() {

    return (
      //原因：从登陆界面跳转到MainScreen页面使用了Stacknavigator控件
      //解决办法：1.将控件中的navigationoption取消掉
      //2.换一种跳转方式
      <LoginRout></LoginRout>
      // <MainScreenNavigator>
      // </MainScreenNavigator>
    );
  }
}

